-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for app shell navigation via AMP Shadow DOM #1519
base: develop
Are you sure you want to change the base?
Conversation
Note that travis is failing due to Gutenberg being merged into core. |
e2df4ed
to
039ef47
Compare
…dd/spa-amp-shadow-dom
…dd/spa-amp-shadow-dom
…dd/spa-amp-shadow-dom
20914dd
to
84a2749
Compare
SPA with amp shadow DOM extras
Co-authored-by: Piotr Delawski <[email protected]>
Co-authored-by: Piotr Delawski <[email protected]>
Building the app shell JS with webpack allows us to use third-party code (e.g. @WordPress packages) easily. We also take advantage of the code minification and babel transpilation. This is a step towards using @wordpress/hooks package in the app shell script.
The change to the inner component URL format introduced in 6054285 broke the app shell experience. While URL format (use an URL segment instead of a query parameter) was changed in the JS implementation, the back-end PHP handler was still expecting the old format. It resulted in loading 404 pages instead of actual inner components for requested pages. The follow up commit will allow altering of the URL format if a plugin integrator really needs to do so.
In some cases, the plugin integrator may need to alter the format of the inner component URL. While it is possible to change the way incoming requests for inner components are handled on the back-end (PHP), there was no way to change the URL format of the request on the front-end (JS). This commit makes the inner component request URL filterable using wp.hooks. Here's how you could filter the URL in your plugin or theme so that instead of using a query parameter, a new segment is added to the URL: ``` if ( ampAppShell && ampAppShell.hooks ) { function filterInnerComponentUrl( url, baseUrl, componentQueryVar ) { const filteredUrl = new URL( baseUrl ); const pathSuffix = '_' + componentQueryVar + '_inner'; filteredUrl.pathname = filteredUrl.pathname + pathSuffix; return filteredUrl; } ampAppShell.hooks.addFilter( 'amp.appShell.innerComponentUrl', 'ampWpAppShell/filterInnerComponentUrl', filterInnerComponentUrl ); } ```
Allow filtering of inner component URL
* develop: (2551 commits) Update dependency eslint-plugin-jest to v23.18.2 Update dependency eslint-plugin-jest to v23.18.1 Fix TikTok test Fix test failure in WP 4.9 Add tests for ObsoleteBlockAttributeRemover Skip adding data attributes for gallery shortcodes Revert block deprecation logic Harden pattern to match block comment and start tag Improve phpdoc for ObsoleteBlockAttributeRemover Improve logic for obtaining obsolete attribute pattern Introduce ObsoleteBlockAttributeRemover service Update dependency webpack to v4.44.0 Modify the block attributes during its deprecation Use DOMElement as return type for HasCaption::get_caption_element() Prevent removal of data attributes in sanitize_raw_embeds and fix boolean checks Ensure data-amp-carousel=true attribute is present for proper styling of gallery block Supply missing attribute value for gallery shortcode output Ensure comments_popup_link() is also filtered to prevent mobile redirection Test AMP_Theme_Support::amend_comments_link Remove unused imports ... # Conflicts: # amp.php # includes/amp-helper-functions.php # includes/class-amp-theme-support.php # includes/sanitizers/class-amp-style-sanitizer.php # includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php
Merge develop and resolve conflicts
Plugin builds for 77fca7d are ready 🛎️!
|
This is a first step of a migration of an app shell experimental implementation proposed in ampproject/amp-wp#1519
In the original app shell implementation proposed in ampproject/amp-wp#1519 the is_amp_endpoint() function was modified in order to return true if an inner component was requested. In order to achieve the same effect without altering the original is_amp_endpoint() implementation, we're explicitly asking for an AMP document when requesting the inner component. Simply, an AMP slug is appended to a URL when fetching a new page.
|
Note: This is somewhat of a prototype for what could be supported in AMP itself as seamless page transitions: ampproject/amphtml#12981 / ampproject/amphtml#14738
For a theme to support app shell via the AMP plugin, the bare minimum that needs to be done is:
functions.php
:offline.php
template in your theme.You should mark for precaching any scripts and stylesheets needed by the app shell. This can be done via:For theme which adds support for AMP app shell see https://github.com/xwp/twentyseventeen-westonson. Note that this theme copies some code from the Twenty Seventeen parent theme in order to add make the necessary modifications. For example, the
js/global.js
file modified as per this diff. The theme has app shell behind a theme mod flag, so make sure you dowp theme mod set service_worker_navigation amp_app_shell
via WP-CLI. See also how it adds skeleton content to the app shell. See also plugin to enable stale-while-revalidate caching strategy for navigation requests.This was presented at CDS 2018; see related portion of talk.
For a demo of the app shell theme in action, see https://dev-showcase-pwa.pantheonsite.io/
See also this short screen cast: https://youtu.be/oAiIbhHdoXM
For some more background on this, see GoogleChromeLabs/pwa-wp#12 (comment)
Todo
style
andlink
elements get preserved during content isolation.outer
shell request.title
.body
classes.Flag that the deprecation of the non-streaming API would break this.When declaring theme support, include the script handles to print in addition to shadow API script.link
,meta
, JSON-LD, etc)?amp
to not-?amp
. If such a redirect happens, navigate the entire page.#
anchor link.